package com.example.weather.logic.dao

import android.content.Context
import android.content.SharedPreferences
import androidx.lifecycle.liveData
import com.example.common.MyApplication
import com.example.common.extend.edit
import com.example.weather.logic.model.Place
import com.google.gson.Gson

object PlaceDao {

    private val mSPName = "apiSharedP"
    fun savePlace(place: Place) {
        sharedPreferences().edit {
            putString("place", Gson().toJson(place))
        }
    }

    fun getSavePlace(): Place {
        val savePlace = sharedPreferences().getString("place", "")
        return Gson().fromJson(savePlace, Place::class.java)
    }

    fun isPlaceSaved(): Boolean {
        return sharedPreferences().contains("place")
    }

    private fun sharedPreferences() = MyApplication.sInstener.getSharedPreferences(mSPName, Context.MODE_PRIVATE)

}